const connect = require('connect');
const path = require('path');
const serveFavicon = require('serve-favicon');
const expressSession = require('express-session');

const favicon = path.join(__dirname, 'favicon.ico');

const app = connect()
  .use(serveFavicon(favicon))
  .use(expressSession({ secret: 'keyboard cat' }))
  .use(function (req, res, next) {
    const sess = req.session;
    if (sess.views) {
      res.setHeader('Content-Type', 'text/html');
      res.write(`<p>views : ${sess.views}</p>`);
      res.end();
    } else {
      sess.views = 1;
      res.end('welcome to the session demo. refresh!');
    }
  });

app.listen(3000);
